home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1035
/
1035.xpi
/
chrome
/
1clickweather.jar
/
content
/
1clickweather
/
js
/
common.js
< prev
next >
Wrap
Text File
|
2010-01-04
|
6KB
|
229 lines
// � 2005 The Weather Channel Interactive, Inc. All Rights Reserved.
var GlobalTimerHash = {};
var GlobalJsIncludeFiles = {};
// this is a pretty darn cool function. It can load up javascript using chrome:// urls
function jsInclude(inputFile){
// this is a simple way to make sure we don't reload an already loaded js file
if(typeof(GlobalJsIncludeFiles[inputFile]) == "undefined"){
try{
var obj = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
if(obj){
obj.loadSubScript(inputFile);
GlobalJsIncludeFiles[inputFile] = true;
return true;
}else{
return false;
}
}
catch(e){
alert("file: " + inputFile + "\n" + e.message);
return false;
}
}else{
return(false);
}
}
jsInclude("chrome://1clickweather/content/js/utils/debug.js");
function openXUL(xulFile, key, val){
try{
var obj = new Object();
obj.data = {};
obj.data[key] = val;
window.openDialog('chrome://1clickweather/content/' + xulFile, '_blank', 'centerscreen, resizable, chrome, alwaysRaised, close', obj).focus();
}catch(e){
alert("Error opening window: " + xulFile + " " + e);
}
}
function hashSize(myHash) {
var i = 0;
for(var nk in myHash) {
i++;
}
return(i);
}
function getBrowserWindow(){
var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
var winHandle = windowManagerInterface.getMostRecentWindow("navigator:browser");
if (!winHandle)
winHandle = window.openDialog("chrome://browser/content/browser.xul", "_blank", "chrome,all,dialog=no", "about:blank", null, null);
return(winHandle);
}
function openLinkInNewTab(aURL) {
var win = getBrowserWindow();
var browser = win.document.getElementById("content");
var tab = browser.addTab(aURL);
browser.selectedTab = tab;
win.content.focus();
}
function ascending(a,b){
return a-b;
}
function hash2array(h){
d = new Array();
for(var i in h){
d.push(i);
}
return(d.sort(ascending));
}
function sleep(i){
setTimeout(setVar, i);
}
function setVar(){
var x = 1;
}
function now(){
var d = new Date();
return(d.toLocaleString());
}
function isAfterTimeSwitch(timeStr){
var timeArray = timeStr.split(/ /);
var localTime = timeArray[0].split(/:/);
if(timeArray[1] == 'PM'){
/*
var localTime = timeArray[0].split(/:/);
*/
if(((localTime[0] >= 2) && (localTime[0] < 12)) || (localTime[0] == 0)){
return(true);
}
}else{
/*
var localTime = timeArray[0].split(/:/);
*/
if(localTime[0] == 12){
return(true);
}
}
return(false);
}
function oTimer(f){
this.Timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
this.delay = 10; // default to 10 seconds
this.type = Components.interfaces.nsITimer.TYPE_ONE_SHOT;
this.note = '';
if(f){
this.Func = f;
}else{
this.Func = null;
}
this.setDelay = function(interval){
this.delay = interval;
}
this.setNote = function(n){
this.note = n;
}
this.setType = function(type){
switch(type){
case 'once':
this.type = Components.interfaces.nsITimer.TYPE_ONE_SHOT;
break;
case 'repeat':
this.type = Components.interfaces.nsITimer.TYPE_REPEATING_SLACK;
break;
}
}
this.setFunction = function(f){
this.Func = f;
}
this.Start = function(){
if(this.Func){
// debugLog("starting timer " + this.note);
this.Timer.initWithCallback(this, (1000 * this.delay), this.type);
}
}
this.Stop = function(){
// debugLog("stopping timer " + this.note);
this.Timer.cancel();
}
this.notify = function(aTimer){
debugLog("firing timer " + this.note);
this.Func();
}
}
function interClickDay0(event) {
var win = getBrowserWindow();
if(event.button==0 || event.button==1) {
openLinkInNewTab(win.document.getElementById("statusbar-container.Day0.box").getAttribute("uri"));
} else {
callSetup();
}
}
function interClickDay1(event) {
var win = getBrowserWindow();
if(event.button==0 || event.button==1) {
openLinkInNewTab(win.document.getElementById("statusbar-container.Day1.box").getAttribute("uri"));
} else {
callSetup();
}
}
function interClickDay2(event) {
var win = getBrowserWindow();
if(event.button==0 || event.button==1) {
openLinkInNewTab(win.document.getElementById("statusbar-container.Day2.box").getAttribute("uri"));
} else {
callSetup();
}
}
function interClickDay3(event) {
var win = getBrowserWindow();
if(event.button==0 || event.button==1) {
openLinkInNewTab(win.document.getElementById("statusbar-container.Day3.box").getAttribute("uri"));
} else {
callSetup();
}
}
function interClickDay4(event) {
var win = getBrowserWindow();
if(event.button==0 || event.button==1) {
openLinkInNewTab(win.document.getElementById("statusbar-container.Day4.box").getAttribute("uri"));
} else {
callSetup();
}
}
function interClickCurrent(event) {
var win = getBrowserWindow();
if(event.button==0 || event.button==1) {
openLinkInNewTab(win.document.getElementById("statusbar-container.CurrentCond.box").getAttribute("uri"));
} else {
callSetup();
}
}